package demo01Object;

import java.util.Objects;

public class demo02Zi {
    private String name;
    private int age;

    public demo02Zi() {
    }

    public demo02Zi(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //默认比较两个对象的地址值没有意义，重写equlse方法
    /*
    问题：
        equals隐含这一个多态，多态无法使用子类特有的方法
    解决：
        向下转型
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof demo02Zi)) return false;
        demo02Zi demo02Zi = (demo02Zi) o;
        return age == demo02Zi.age &&
                Objects.equals(name, demo02Zi.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
